package cn.pugle.base.nio;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created by tzp on 15-10-21.<br/>
 *
 * FileChannel无法设置为非阻塞模式，它总是运行在阻塞模式下。....
 */
public class FileChannelTest {
    public static void main(String[] args) throws Exception {
        RandomAccessFile aFile = new RandomAccessFile("/home/tzp/linshirenwu/data/10065", "r");
        FileChannel inChannel = aFile.getChannel();
        ByteBuffer buf = ByteBuffer.allocate(480 * 1024 * 1024);
        System.out.println(System.currentTimeMillis());
        int bytesRead = inChannel.read(buf);
        System.out.println(System.currentTimeMillis());
        System.out.println("do something else");
        System.out.println(bytesRead);
        System.out.println(48 * 1024 * 1024);
//        while (bytesRead != -1) {
//            System.out.println("------------------Read " + bytesRead);
//            buf.flip();
////            while (buf.hasRemaining()) {
////                System.out.println(new String(buf.array()));
////            }
//            System.out.println(new String(buf.array()));
//            buf.clear();
//            bytesRead = inChannel.read(buf);
//        }
        aFile.close();
    }
}

// java.io
//        FileInputStream fileInputStream = new FileInputStream("/home/tzp/docs/mailTagIncrease.sh");
//        BufferedReader br = new BufferedReader(new InputStreamReader(fileInputStream,"utf-8"));
//        System.out.println(br.readLine());
//        byte[] bytes = new byte[100];
//        fileInputStream.read(bytes);
//        System.out.println(bytes[10]);

//        FileChannel inChannel =fileInputStream.getChannel();